//
//  MineClassCell.m
//  ForestPack
//
//  Created by 郑洲 on 2018/7/4.
//  Copyright © 2018年 郑洲. All rights reserved.
//

#import "MineClassTableViewCell.h"

@implementation MineClassTableViewCell

+ (MineClassTableViewCell *)cellWithTableView:(UITableView *)tableView andIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellID = @"MineClassTableViewCell";
    MineClassTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[MineClassTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.backgroundColor = [UIColor whiteColor];
        [cell createSubView];
    }
    
    return cell;
}

- (void)createSubView {
    NSArray *nameArr = @[@"心愿订单",@"购买清单",@"地址管理",@"联系客服",@"邀请好友",@"设置"];
    NSArray *imageArr = @[@"心愿单",@"购买清单",@"地址管理",@"联系客服",@"邀请好友",@"设置-2"];
    CGFloat width = (SCREEN_WIDTH - ScreenX375(32)) / 2;
    CGFloat height = ScreenX375(220) / 3;
    for (int i = 0; i < nameArr.count; i++) {
        UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(i % 2 * width + ScreenX375(16), i / 2 * height + ScreenX375(20), width, height)];
        [self addSubview:bgView];
        
        UIButton *icon = [[UIButton alloc] initWithFrame:CGRectMake((width - ScreenX375(22)) / 2, ScreenX375(17), ScreenX375(19), ScreenX375(19))];
        [icon setImage:[UIImage imageNamed:imageArr[i]] forState:UIControlStateNormal];
        [bgView addSubview:icon];
        
        UILabel *nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, ScreenX375(39), width, ScreenX375(18))];
        nameLabel.text = nameArr[i];
        nameLabel.textAlignment = NSTextAlignmentCenter;
        nameLabel.font = Kfont(13);
        nameLabel.textColor = REXADECIMALCOLOR(@"#9b9b9b");
        [bgView addSubview:nameLabel];
        
        UIButton *classBtn = [[UIButton alloc] initWithFrame:CGRectMake(i % 2 * width + ScreenX375(16), i / 2 * height + ScreenX375(20), width, height)];
        classBtn.backgroundColor = [UIColor clearColor];
        classBtn.tag = 100 + i;
        [classBtn addTarget:self action:@selector(classClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:classBtn];
    }
    
    for (int i = 0; i < 2; i++) {
        UIView *sLine = [[UIView alloc] initWithFrame:CGRectMake((i + 1) * width + ScreenX375(16), ScreenX375(20), 0.5, ScreenX375(220))];
        sLine.backgroundColor = REXADECIMALCOLOR(@"#e4e4e4");
        if (i == 0) {
            [self addSubview:sLine];
        }
        
        UIView *hLine = [[UIView alloc] initWithFrame:CGRectMake(ScreenX375(16), (i + 1) * height + ScreenX375(20), (SCREEN_WIDTH - ScreenX375(32)), 0.5)];
        hLine.backgroundColor = REXADECIMALCOLOR(@"#e4e4e4");
        [self addSubview:hLine];
    }
}

- (void)classClick:(UIButton *)btn{
    if (_indexClick) {
        _indexClick(btn.tag - 100);
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
